/*
 * 作者: 张帆
 * 时间: 2017-04-12 
 * 说明：
 * Copyright (c) 2016-2017 中研沃兮
 */
define(function(require) {
	
	require("jquery");

	var c = require('app/utils/CommonUtils');
	var APIUtils = require('app/utils/APIUtils');
	var appInfo = require('app/AppInfo');
	var action_search = require('app/action/SearchIconFrmAction');
	var hc = require('app/utils/HttpClientUtils');
	var EventUtils=require('app/utils/EventUtils');
	var param = api.pageParam;
	
	$(".aui-title").text(param.title);
	function getEnrolldata(){   		
       var url=appInfo.serverbase + "/luyan/form/"+param.formid+"/records";
       var body={};
       hc.post(url,body,function(resp){
       		if(resp.status==200){
       			resp.result.records.forEach(function(item,key){
		       		dom='<li class="aui-list-item">'+
				            '<div class="aui-list-item-inner aui-list-item-arrow">'+
				                '<div class="aui-list-item-title" style="text-overflow:ellipsis;overflow: hidden;white-space: nowrap;">'+
				                	+(key+1)+'. <span id="detial_name">'+item.field1.fieldvalue+'</span>'+
				                '</div>'+
				            '</div>'+
			        	'</li>'
		      		$('#enrollmessage').append(dom);
		      		$("#enrollmessage li").eq(key).on("click",function(){
		      			var p=param;
		      			p.type="change";
		      			p.formData=item;
		      			p.recordid=item.field1.recordid;
		      			p.formId=param.formid;
		      			p.formList=resp.result.fields;
						api.openWin({
					        name: 'EnrollDetailsWin',
					        url: './EnrollDetailsWin.html',
					        pageParam:p
				        });
		      		})
		
       			})    
       			$("#addData").click(function(){
		      		var p=param;
		      		p.type="add";
		      		p.formId=param.formid;
		      		p.formData=[];
		      		p.formList=resp.result.fields;
					api.openWin({
					    name: 'EnrollDetailsWin',
					    url: './EnrollDetailsWin.html',
					    pageParam:p
				    });
				});		  			  
       		}
       })
    }
    getEnrolldata()
	$("#back").click(function(){
		api.closeWin({
	    });
	});
	EventUtils.listen(api.winName, 'refresh_enroll_list', false, function(data){
		location.reload()
	});

	return;
});